<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>打开MS SQL server链接</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mssql-connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mssql_connect</h1>
  <p class="verinfo">(PHP 4, PHP 5, PECL odbtp &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">mssql_connect</span> &mdash; <span class="dc-title">打开MS SQL server链接</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.mssql-connect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mssql_connect</strong></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$servername</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$username</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$new_link</code><span class="initializer"> = false</span></span>
  ]]]] ) : <span class="type">resource</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>mssql_connect()</strong></span> 建立一个MS SQL server链接。
  </p>
  <p class="para">
   链接会在程序执行结束之后关闭, 除非在之前已经通过调用<span class="function"><a href="mssql_close.html" class="function">mssql_close()</a></span>关闭。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mssql-connect-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">servername</code></dt>

     <dd>

      <p class="para">
       服务器,它可以包含一个端口号 e.g.
       <em>主机:端口号(hostname:port)</em> (Linux), 或 
       <em>主机,端口号(hostname,port)</em> (Windows).
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">username</code></dt>

     <dd>

      <p class="para">
       用户名。 
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">password</code></dt>

     <dd>

      <p class="para">
       密码。 
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">new_link</code></dt>

     <dd>

      <p class="para">
       如果第二次调用<span class="function"><strong>mssql_connect()</strong></span>使用相同的参数，
       不会建立新的链接，而是将之前已经打开的链接标识返回。对这个参数的值进行修改，则使得调用 
       <span class="function"><strong>mssql_connect()</strong></span>总是会建立新的链接，
       即便调用<span class="function"><strong>mssql_connect()</strong></span>使用与之前同样的参数。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mssql-connect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回一个链接视为成功, 或者 <strong><code>FALSE</code></strong> 和错误信息.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mssql-connect-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.0</td>
       <td>
        <code class="parameter">new_link</code>参数加入
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mssql-connect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1748">
    <p><strong>Example #1 <span class="function"><strong>mssql_connect()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Server&nbsp;in&nbsp;the&nbsp;this&nbsp;format:&nbsp;&lt;computer&gt;\&lt;instance&nbsp;name&gt;&nbsp;or&nbsp;<br />//&nbsp;&lt;server&gt;,&lt;port&gt;&nbsp;when&nbsp;using&nbsp;a&nbsp;non&nbsp;default&nbsp;port&nbsp;number<br /></span><span style="color: #0000BB">$server&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'KALLESPC\SQLEXPRESS'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Connect&nbsp;to&nbsp;MSSQL<br /></span><span style="color: #0000BB">$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$server</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sa'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phpfi'</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Something&nbsp;went&nbsp;wrong&nbsp;while&nbsp;connecting&nbsp;to&nbsp;MSSQL'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mssql-connect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mssql_close.html" class="function" rel="rdfs-seeAlso">mssql_close()</a> - 关闭MS SQL Server链接</span></li>
    <li class="member"><span class="function"><a href="mssql_pconnect.html" class="function" rel="rdfs-seeAlso">mssql_pconnect()</a> - Open persistent MS SQL connection</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>